package club.laowang.chain.validation;

import java.util.ArrayList;
import java.util.List;

public class ValidatorChain {
    private List<ValidatorHandler> handlers = new ArrayList<>();

    private ValidatorContext context = new ValidatorContext();

    public ValidatorChain() {
    }

    public ValidatorChain(ValidatorContext context) {
        this.context = context;
    }

    public void addLastHandler(ValidatorHandler handler) {
        this.handlers.add(handler);
    }

    public void validate(Object value) {

        for (ValidatorHandler handler : handlers) {
            handler.validator(value, context);
        }
//        context.throwExceptionIfNecessary();
    }
}
